package com.ryan.demo.xstream.mas.parser;

import org.apache.log4j.Logger;

import com.ryan.demo.xstream.mas.model.AbstractMOReqMsg;
import com.ryan.demo.xstream.mas.model.MOReqMsg;
import com.ryan.demo.xstream.mas.model.MOResMsg;
import com.ryan.demo.xstream.mas.parser.converter.ReflectionExtConverter;
import com.thoughtworks.xstream.XStream;


/**
 * @Project mas
 * @Description 默认报文解析器
 * @Company 99bill
 * @Create 2012-1-29
 * @author frank.wu
 */

public class MasRequestParser {

	protected static final Logger logger = Logger.getLogger(MasRequestParser.class);
	/**
	 * 请求XML->TO映射器
	 */
	private static final XStream xstream = new XStream();
	
	static{
//		xstream.registerConverter(new ReflectionExtConverter(xstream.getMapper(),xstream.getReflectionProvider()), XStream.PRIORITY_VERY_LOW);
		xstream.processAnnotations(new Class<?>[]{MOReqMsg.class, MOResMsg.class});		
	}
	
	public AbstractMOReqMsg parseReq(String message) {
		MOReqMsg moGrpReqMsg = (MOReqMsg)xstream.fromXML(message);
		return moGrpReqMsg;
	}
	public String parseReq(AbstractMOReqMsg message) {
		String xml = xstream.toXML(message);
		return xml;
	}
	
	public String parseRes(MOResMsg message){
		String xml = xstream.toXML(message);
		return xml;
	}

}
